package com.szh.cloud.api.teacher.service.impl;

import com.szh.cloud.api.teacher.entity.SearTeacherEntity;
import com.szh.cloud.api.teacher.repository.ApiTeacherDao;
import com.szh.cloud.api.teacher.service.ApiTeacherService;
import com.szh.cloud.mybatis.entity.PtTeacherEntity;
import com.szh.cloud.mybatis.etable.ElTable;
import com.szh.cloud.mybatis.flexigrid.PagingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ApiTeacherServiceImpl implements ApiTeacherService {
    @Autowired
    private ApiTeacherDao teacherDao;

    @Override
    public Map<String, Object> queryTeachers(SearTeacherEntity params) {
        List<SearTeacherEntity> list = teacherDao.queryTeachers(params);
        Long total = teacherDao.countTeachers(params);

        Map<String, Object> result = new HashMap<>();
        result.put("list", list);
        result.put("total", total);
        return result;
    }

    @Override
    public SearTeacherEntity getTeacherById(String tchrUuid) {
        return teacherDao.getTeacherById(tchrUuid);
    }

    @Override
    @Transactional
    public boolean addTeacher(SearTeacherEntity teacher) {
        teacher.setDelFlag(0);
        return teacherDao.insertTeacher(teacher) > 0;
    }

    @Override
    @Transactional
    public boolean updateTeacher(SearTeacherEntity teacher) {
        return teacherDao.updateTeacher(teacher) > 0;
    }

    @Override
    @Transactional
    public boolean deleteTeacher(String tchrUuid) {
        return teacherDao.deleteTeacher(tchrUuid) > 0;
    }

    @Override
    @Transactional
    public boolean batchDeleteTeachers(List<String> ids) {
        return teacherDao.batchDeleteTeachers(ids) > 0;
    }
}
